package model

type Member struct {
	Id    int64  `xorm:"'id'"`
	Name  string `xorm:"varchar(255) notnull unique 'name'"`
	Pass  string `xorm:"varchar(255) notnull 'pass'"`
	Token string `xorm:"text 'token'"`
}

func (Member) Add(name, pass string) (err error) {
	data := &Member{
		Name: name,
		Pass: pass,
	}
	_, err = engine.Insert(data)
	return err
}
func (Member) UpdateToken(token string, id int64) (err error) {
	data := &Member{
		Token: token,
	}
	_, err = engine.Id(id).Update(data)
	return err
}
func (Member) FindOne(name string) (userInfo *Member, err error) {
	userInfo = &Member{
		Name: name,
	}
	has, err := engine.Get(userInfo)
	if !has {
		return nil, err
	}
	return userInfo, err
}
func (Member) FindOneById(id int64) (userInfo *Member, err error) {
	userInfo = &Member{
		Id: id,
	}
	has, err := engine.Get(userInfo)
	if !has {
		return nil, err
	}
	return userInfo, err
}
func (Member) RemoveOne(id int64) (err error) {
	data := &Member{
		Id: id,
	}
	_, err = engine.Delete(data)
	return err
}
